<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <form action="" class="layui-form" lay-filter="procterForm">
            <div class="layui-form-item">
                <label class="layui-form-label required">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="procter_name" lay-verify="required" lay-reqtext="姓名不能为空"
                        placeholder="请输入姓名" value="" class="layui-input">
                    <!-- <tip>填写自己管理账号的名称。</tip> -->
                </div>
            </div>

            <input type="hidden" name="procter_id" class="layui-input">
            <div class="layui-form-item">

                <label class="layui-form-label required">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="procter_sex" value="男" title="男" checked="">
                    <input type="radio" name="procter_sex" value="女" title="女">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">生日</label>
                <div class="layui-input-block">
                    <input type="text" name="procter_birthday" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                        autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">手机</label>
                <div class="layui-input-block">
                    <input type="text" name="procter_phone" lay-verify="required" lay-reqtext="手机不能为空"
                        placeholder="请输入手机" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" name="procter_address" placeholder="请输入地址" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>

        </form>
    </div>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                $ = layui.$;

            // 渲染日期组件
            laydate.render({
                elem: '#date'
            });

            //从localStorage 把数据取出来  赋值给表单项
            var jsonStr = localStorage.getItem("procter");
            var procterObj = JSON.parse(jsonStr);
            //给表单项赋值
            form.val("procterForm",{
                procter_id: procterObj.procter_id,
                procter_name: procterObj.procter_name,
                procter_sex: procterObj.procter_sex,
                procter_birthday: procterObj.procter_birthday,
                procter_phone: procterObj.procter_phone,
                procter_address: procterObj.procter_address
            })



            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {

                    // 关闭弹出层
                    layer.close(index);

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });

                $.ajax({
                    url: "http://localhost:8080/procter/updateProcter",
                    data: data.field,
                    type: "post",
                    success: function (result) {
                        if (result.code == 0) {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改成功");
                            parent.layer.close(iframeIndex);

                        } else {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改失败");
                            parent.layer.close(iframeIndex);
                        }
                    },
                    dataType: "json"
                })
                return false;
            });
        });
    </script>
</body>

</html>